package com.edu.entity;

import lombok.Data;

import java.util.Set;

@Data
public class User implements java.io.Serializable {
    private Integer id;
    private String username;
    private String password;
    private String email;
    private String sex;
    private String tel;
    private String headImg;
    private String type;
    private String createTime;

    private Integer roleId;   //添加一个属性[辅助属性]

    //{1}新增属性项..
    private Set<Role> roles;
    public User(){}
    public User(Integer id, String headImg){
        this.id = id;
        this.headImg = headImg;
    }

    public String getRoleName(){
        if( roles!=null ){
            Role R = roles.iterator().next();
            return R.getRoleName();
        }
        return "未知角色";
    }

    public Role getPrimaryRole() {
        Role R = new Role();
        R.setId(0);
        R.setRoleName("未分配角色");
        if (roles!= null){
            if (roles.size()>0){
                return roles.iterator().next();
            }
        }
        return R;
    }
}
